<?php
header('content-type:text/html;charset=utf8');
require_once "../../config.php";
require_once "../../functions.php";
//完成用户的登录
// print_r($_POST);
//1. 获取邮箱和密码
$email = $_POST['email'];
$password = $_POST['password'];
//2.根据邮箱和密码到数据库中去取数据
//2.1连接数据库
$connect = connect();
//2.2准备sql语句
$sql = "select * from users where email = '{$email}' and password = '{$password}' and status = 'activated';";
//2.3执行sql
$queryResult = query($connect,$sql);
// print_r($queryResult);
$response = ["code"=>0,"msg"=>"操作失败"];
if($queryResult){
    session_start();
    $_SESSION['isLogin'] = 1;
    //把用户的id存起来
    $_SESSION['user_id'] = $queryResult[0]['id'];
    $response["code"] = 1;
    $response["msg"] = "操作成功";
}
header("content-type:application/json;charset=utf-8");
echo json_encode($response);
?>